//
//  HCStoreRecommendViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/2/8.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCStoreRecommendViewController.h"

#import "HCStoreRecommendView.h"

#import "CCLocationManager.h"

#import "HCFindStoreRecModel.h"

#import "HCLogViewController.h"

@interface HCStoreRecommendViewController () <HCStoreRecommendViewClicked> {
    HCFindStoreRecModel *modelRec;
    HCStoreRecommendView *reView;
    HCPopLoadingView *popLoading;
}

@end

@implementation HCStoreRecommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.textTitle = @"店家推荐";
    
    self.dataRequest.delegate = self;
    popLoading = [[HCPopLoadingView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [popLoading showAnimate];
    [self initializeRecommend];
    
    __block __weak HCStoreRecommendViewController *weakself = self;
    
    [[CCLocationManager shareLocation] getCity:^(NSString *addressString) {
        NSLog(@"获得的地址:%@",addressString);
        if ([PublicFunction isNull:HCGETUSER(@"userid")]) {
            [popLoading hidden];
//            HCLogViewController *log = [[HCLogViewController alloc] init];
//            
//            UINavigationController *na = [[UINavigationController alloc] initWithRootViewController:log];
//            na.navigationBarHidden = YES;
//            [weakself.navigationController presentViewController:na animated:YES completion:nil];
        }else{
            [weakself.dataRequest postHC_StoreRecommand:HCGETUSER(@"userid") userCity:@"成都"];
        }
    }];
    
    
    // Do any additional setup after loading the view.
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {
    NSLog(@"店家推荐成功:%@",dictionary);
    modelRec = [[HCFindStoreRecModel alloc] initWithDictionary:dictionary error:nil];
    reView.model = modelRec;
    [popLoading hidden];
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {
    NSLog(@"店家推荐失败");
    [popLoading hidden];
}

-(void)storeRecommendUrl:(NSString *)url {
    [self pushChildrenViewController:@"HCRecomDetailViewController" parameterObject:url dataObject:nil];
}

-(void)initializeRecommend {
    reView = [[HCStoreRecommendView alloc] initWithFrame:CGRectMake(0, 0, self.centerView.frame.size.width, self.centerView.frame.size.height)];
    reView.backgroundColor = YBKRGBCOLOR(241, 241, 241, 1);
    reView.delegate = self;
    [self.centerView addSubview:reView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
